<script setup >

import {onMounted,ref} from 'vue'
import {getScheduleList} from '../api/schedule.js'
import {useRouter}  from 'vue-router'


/*
数组的赋值比较特殊，常见的两种简单的方式是：
① 将数组封装到一个对象中，假设这个对象叫: 
  let scheduleData=reactive({
    tableData:[]
  })
  scheduleData.tableData = data.data;
② 将数组使用ref修饰
  let tableData = ref([])
  tableData.value=data.data
*/
let tableData = ref([
  
])

onMounted(()=>{
  loadScheduleList()
})
let loadScheduleList = async ()=>{
  let data = await getScheduleList()
  tableData.value = data.data
}

let router = useRouter()

let toAdd=()=>{
    router.push("/add")
}
</script>

<template>
  <div>
    <el-button type="primary" plain @click="toAdd">新增</el-button>
    <el-table :data="tableData" style="width: 100%">
    <el-table-column label="编号" width="180">
      <template #default="scope">
        <div style="display: flex; align-items: center">
          <span style="margin-left: 10px">{{ scope.row.id }}</span>
        </div>
      </template>
    </el-table-column>
    <el-table-column label="学习计划" width="180">
      <template #default="scope">
        <span style="margin-left: 10px">{{ scope.row.title }}</span>
      </template>
    </el-table-column>
    <el-table-column label="是否完成" width="180">
      <template #default="scope">
        <span style="margin-left: 10px">{{ scope.row.completed ? "已完成" : "未完成" }}</span>
      </template>
    </el-table-column>
    <el-table-column label="其他操作">
      <template #default="scope">
        <el-button >编辑</el-button>
        <el-button type="danger">删除</el-button>
      </template>
    </el-table-column>
  </el-table>

  </div>
  
</template>